#include "SampleSelector.h"
#include "imgui.h"

// ===========Basic Samples ============
#include "TriangleSample.h"
#include "SphereSample.h"
#include "NormalSample.h"
#include "MSAASample.h"
// ===========Material Samples ============
#include "DiffuseSample.h"
#include "MetalSample.h"
#include "GlassSample.h"

// ===========Camera Samples ============
#include "CameraSample.h"
// ===========Primitive Samples ============
#include "PrimitiveSample.h"
#include "RectPrimitiveSample.h"
#include "BoxPrimitiveSample.h"
#include "SkyBoxSample.h"
#include "LightSample.h"
#include "CornellBox.h"
#include "CornellBoxLightSample.h"
namespace RayTracer 
{

	SampleSelector::SampleSelector() 
	{
		mCurrentSample = nullptr;
	}

	SampleSelector::~SampleSelector() 
	{
		if (mCurrentSample) 
		{
			delete mCurrentSample;
		}
	}

	SampleBase* SampleSelector::GetCurrentSample() 
	{
		return mCurrentSample;
	}

	void SampleSelector::Initialize() 
	{
	
	}

	void SampleSelector::Update(float inDeltaTime) 
	{
		if (mCurrentSample) 
		{
			mCurrentSample->Update(inDeltaTime);
		}
	}
	void SampleSelector::Render() 
	{
		if (mCurrentSample) 
		{
			mCurrentSample->Render();
		}
	}
	void SampleSelector::ImGui() 
	{
		if (mCurrentSample) 
		{
			mCurrentSample->ImGui();
			if (ImGui::Button(u8"Close")) 
			{
				mCurrentSample->ShutDown();
				delete mCurrentSample;
				mCurrentSample = nullptr;
			}
		}
		else {
			// Title
			ImGui::Text("Ray Tracer Engine");
			ImGui::Separator();
			// basic samples
			if (ImGui::CollapsingHeader(u8"Basic Samples")) 
			{
				// Background
				if (ImGui::Button(u8"Gradient Sky")) 
				{
					mCurrentSample = new TriangleSample();
					mCurrentSample->Init();
				}
				// Sphere
				if (ImGui::Button(u8"Sphere")) 
				{
					mCurrentSample = new SphereSample();
					mCurrentSample->Init();
				}
				// Normal
				if (ImGui::Button(u8"Normal")) 
				{
					mCurrentSample = new NormalSamples();
					mCurrentSample->Init();
				}
				// MSAA
				if (ImGui::Button(u8"MASS")) 
				{
					mCurrentSample = new MSAASample();
					mCurrentSample->Init();
				}
			}
			// materials
			if (ImGui::CollapsingHeader(u8"Material Samples")) 
			{
				// Diffuse Material
				if (ImGui::Button(u8"Diffuse Materials"))
				{
					mCurrentSample = new DiffuseSample();
					mCurrentSample->Init();
				}

				// Metal Material
				if (ImGui::Button(u8"Metal Materials"))
				{
					mCurrentSample = new MetalSample();
					mCurrentSample->Init();
				}

				// Glass Material
				if (ImGui::Button(u8"Glass Materials"))
				{
					mCurrentSample = new GlassSample();
					mCurrentSample->Init();
				}
			}

			// ========== Camera ============
			if (ImGui::CollapsingHeader(u8"Camera Samples"))
			{
				// Camera
				if (ImGui::Button(u8"Position Camera"))
				{
					mCurrentSample = new CameraSample();
					mCurrentSample->Init();
				}
			}

			// ============= primitive =============
			if (ImGui::CollapsingHeader(u8"Primitive Samples")) 
			{
				// Triangle
				if (ImGui::Button(u8"Triangle Primitive"))
				{
					mCurrentSample = new PrimitiveSample();
					mCurrentSample->Init();
				}
				// Rectangle
				if (ImGui::Button(u8"Rect Primitive"))
				{
					mCurrentSample = new RectPrimitiveSample();
					mCurrentSample->Init();
				}
				// Rectangle
				if (ImGui::Button(u8"Box Primitive"))
				{
					mCurrentSample = new BoxPrimitiveSample();
					mCurrentSample->Init();
				}
				// skybox
				if (ImGui::Button(u8"Box"))
				{
					mCurrentSample = new SkyBoxSample();
					mCurrentSample->Init();
				}

				if (ImGui::Button(u8"Light"))
				{
					mCurrentSample = new LightSample();
					mCurrentSample->Init();
				}
			}
			if (ImGui::CollapsingHeader(u8"CornellBox Samples")) {
				if (ImGui::Button(u8"Cornell Box SkyLight"))
				{
					mCurrentSample = new CornellBoxSample();
					mCurrentSample->Init();
				}

				if (ImGui::Button(u8"Cornell Box RectLight"))
				{
					mCurrentSample = new CornellBoxLightSample();
					mCurrentSample->Init();
				}
			}
		}
	}
	void SampleSelector::Shutdown() 
	{
		if (mCurrentSample) {
			mCurrentSample->ShutDown();
		}
	}
}

